package pro.jiug.kExcel.service.impl;

import org.springframework.web.multipart.MultipartFile;
import pro.jiug.kExcel.entity.HymaxDzts;
import pro.jiug.kExcel.mapper.HymaxDztsMapper;
import pro.jiug.kExcel.service.HymaxDztsService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import pro.jiug.kExcel.utils.AnalysisExcelData;
import pro.jiug.kExcel.utils.IdWorker;

import javax.annotation.Resource;
import java.io.IOException;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author Keffett
 * @since 2021-02-24
 */
@Service
public class HymaxDztsServiceImpl extends ServiceImpl<HymaxDztsMapper, HymaxDzts> implements HymaxDztsService {

    @Resource
    private HymaxDztsMapper hymaxDztsMapper;
    /*
        电子图书Excel导入
     */
    @Override
    public void dztsImportData(MultipartFile fileUpload, int startRow, int endRow, int startCol, int endCol) throws IOException {
        //获取Excel内容
        List<List<String>> excelData = AnalysisExcelData.getExcelData(fileUpload, startRow, endRow, startCol, endCol);

        System.out.println("数据大小：" + excelData.size());

        List<HymaxDzts> hymaxDzts=new ArrayList<>(excelData.size());

        for (List<String> rowList: excelData) {//按行遍历
            if(rowList==null){
                continue;
            }

            HymaxDzts hymaxDztsItem=new HymaxDzts();
            hymaxDztsItem.setId(""+IdWorker.idWork.nextId());

            hymaxDztsItem.setCreateUserId(rowList.get(1));
            hymaxDztsItem.setUpdateOrgId(rowList.get(2));
            hymaxDztsItem.setCreateTime(rowList.get(3));
            hymaxDztsItem.setSubmitTime(rowList.get(4));
            hymaxDztsItem.setCreateOrgId(rowList.get(5));
            hymaxDztsItem.setVersion(rowList.get(6));
            hymaxDztsItem.setDataSource(rowList.get(7));
            hymaxDztsItem.setUpdateTime(rowList.get(8));
            hymaxDztsItem.setClassesId(rowList.get(9));
            hymaxDztsItem.setUpdateUserId(rowList.get(10));
            hymaxDztsItem.setSubmitOrgId(rowList.get(11));
            hymaxDztsItem.setSubmitUserId(rowList.get(12));
            hymaxDztsItem.setStatus(rowList.get(13));
            hymaxDztsItem.setTitle(rowList.get(14));
            hymaxDztsItem.setETitle(rowList.get(15));
            hymaxDztsItem.setAuthor(rowList.get(16));
            hymaxDztsItem.setKeyword(rowList.get(17));
            hymaxDztsItem.setSummary(rowList.get(18));
            hymaxDztsItem.setClassifyCode(rowList.get(19));
            hymaxDztsItem.setLanguage(rowList.get(20));
            hymaxDztsItem.setCover(rowList.get(21));
            hymaxDztsItem.setIsbn(rowList.get(22));
            hymaxDztsItem.setPublishUnit(rowList.get(23));

            BigDecimal num1 = new BigDecimal(rowList.get(24));
            BigDecimal num2 = num1.setScale(2, BigDecimal.ROUND_HALF_UP);
            hymaxDztsItem.setPublishDate(num2.toString());

            hymaxDztsItem.setFile(rowList.get(25));
            hymaxDztsItem.setIsIso(rowList.get(26));
            hymaxDztsItem.setIsoUrl(rowList.get(27));

            hymaxDztsMapper.insert(hymaxDztsItem);

        }



    }
}
